﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Abp;
using Abp.Runtime.Validation;
using pandx.Mulan.Authorization.Users;
using pandx.Mulan.Dto;
using pandx.Mulan.Helpers;

namespace pandx.Mulan.OrganizationUnits.Dto
{
    public class ObtainOrganizationUnitUsersInput : PagedSortedAndFilteredInput, IShouldNormalize
    {
        [Range(0, long.MaxValue)] public long Id { get; set; }
        public List<Gender> Gender { get; set; }
        public List<bool> IsActive { get; set; }

        public void Normalize()
        {
            if (string.IsNullOrEmpty(Sorting))
            {
                if (Id != 0)
                {
                    Sorting = "UserOrganizationUnit.CreationTime DESC";
                }
                else
                {
                    Sorting = "User.Name ASC";
                }
            }
            else if (Sorting.Contains("UserName", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = Sorting.Replace("UserName", "User.UserName", StringComparison.OrdinalIgnoreCase);
            }
            else if (Sorting.Contains("Name", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = Sorting.Replace("Name", "User.Name", StringComparison.OrdinalIgnoreCase);
            }
            else if (Sorting.Contains("AddedTime", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = Sorting.Replace("AddedTime", "UserOrganizationUnit.CreationTime",
                    StringComparison.OrdinalIgnoreCase);
            }

           
        }
    }
}
